<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
//邮件发送
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

function mailto($to,$title,$content)
{
    /*$tos = explode('@',$to);
    if ($tos[1] == 'qq.com') {
        $host = 'smtp.qq.com';
        $usename = '1724130521@qq.com';
        $password = 'svnxkoatvydojfdh';
    } else {

    }*/
    $mail = new \PHPMailer\PHPMailer\PHPMailer(true);
    try {
        //Server settings
        $mail->SMTPDebug = SMTP::DEBUG_OFF;                      // Enable verbose debug output
        $mail->CharSet = 'utf-8';
        $mail->isSMTP();                                            // Send using SMTP
        $mail->Host       = 'smtp.163.com';                    // Set the SMTP server to send through
        $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
        $mail->Username   = '13452297239@163.com';                     // SMTP username
        $mail->Password   = 'ZPAKYGHPNDVOMYUV'; //ZPAKYGHPNDVOMYUV       //                       // SMTP password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
        $mail->Port       = 587;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

        //Recipients
        $mail->setFrom('13452297239@163.com', '梦中程序员');
        $mail->addAddress($to);     // Add a recipient

        // Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = $title;
        $mail->Body    = $content;

        return $mail->send();
    } catch (Exception $e) {
        \exception($mail->ErrorInfo,1001);
    }
}

//产生随机数字验证码(自定义位数)
function random($num)
{
    $key = '';
    $pattern='1234567890';
    for( $i=0; $i<$num; $i++ ) {
        $key .= $pattern[mt_rand(0, 9)];
    }
    return $key;
}

//产生随机[数字+字母]验证码
function rand_captcha($num) {
    $key = '';
    $pattern='1234567890abcdefghijkmnpqrstuvwxyz'; // 无 l o
    for( $i=0; $i<$num; $i++ ) {
        $key .= $pattern[mt_rand(0, 33)];
    }
    return $key;
}

//MD5加密
function md5s($num){
    //加盐值
    $key = 'whitebai@666';
    return md5($num.$key);
}

//把span标签替换成a标签
function replaces($data){
    return str_replace('span','a',$data);
}